export default ({
	name,
	data = {}
}) => {
	/* 导出pormise对象 */
	return new Promise((resolve, reject) => {
		const loading = data.isLoading;
		data.isLoading && delete data.isLoading
		if (loading !== 'noLoding') {
			uni.showLoading({
				title: '加载中'
			})
		}
		uniCloud.callFunction({
			name,
			data,
			success({
				result
			}) {
				if (result.code === 0) {
					resolve(result.data)
				} else {
					console.error('请求失败:', result.msg)
					uni.showToast({
						icon: "none",
						title: result.msg || '请求失败'
					})
					reject(new Error(result.msg || '请求失败'))
				}
			},
			fail(err) {
				console.error('请求错误:', err)
				uni.showToast({
					icon: "none",
					title: '网络错误'
				})
				reject(err)
			},
			complete() {
				if (loading !== 'noLoding') {
					uni.hideLoading()
				}
			}
		})
	})
}